package com.yhp.servlet;

import com.yhp.bean.Grade;
import com.yhp.bean.Student;
import com.yhp.service.impl.GradeServiceImpl;
import com.yhp.service.impl.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/findbyid")
public class FindStudentServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取id值
        int id = Integer.parseInt(req.getParameter("sid"));
        //2.调取service。通过id进行查询
        //2.1获取student信息
        Student student = StudentService.findStudent(id);
        req.setAttribute("student",student);
        //2.2获取年级信息
        List<Grade> grades = new GradeServiceImpl().getList();
        req.setAttribute("grades",grades);
        //3.跳转页面
        req.getRequestDispatcher("edit.jsp").forward(req,resp);
    }
}
